package com.example.liang.basamovie.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.liang.basamovie.R;
import com.example.liang.basamovie.activity.FilmInfoActivity;
import com.example.liang.basamovie.bean.SeleteFilmInfo;
import com.example.liang.basamovie.utils.ImageLoaderUtils;

import java.util.List;

/**
 * 搜索电影item横向滑动的适配器
 */
public class SeleteFilmItemAdapter extends RecyclerView.Adapter<SeleteFilmItemAdapter.MyViewHolder> {
    List<SeleteFilmInfo> list;
    Context context;

    public SeleteFilmItemAdapter(List<SeleteFilmInfo> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.fragment_seleteitem_layout, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {

        final SeleteFilmInfo info = list.get(position);
        holder.Title.setText(info.getTitle());
        holder.countries.setText(info.getCountries());
        holder.year.setText(info.getYear());
        ImageLoaderUtils.getimage(context,info.getImageUrl(),holder.imageView);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context,FilmInfoActivity.class);
                intent.putExtra("id",info.getId()+"&platform=2");
                Log.e("SeleteFilmItemAdapter","---"+info.getId());
                //context.startActivity(intent);
            }
        });


    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        ImageView imageView;
        TextView Title,countries,year;
        public MyViewHolder(View itemView) {
            super(itemView);
            imageView= (ImageView) itemView.findViewById(R.id.seleteItem_iamge);
            Title= (TextView) itemView.findViewById(R.id.seleteItem_FilmName);
            countries= (TextView) itemView.findViewById(R.id.seleteItem_countries);
            year= (TextView) itemView.findViewById(R.id.seleteItem_FilmYear);
        }
    }
}
